package com.smartthinking.dive;

import java.io.File;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;

public class PaginaFacebook extends Activity{

	private static final String HTTPS = "https://";
	private static final String HTTP = "http://";
	String eve_facebook;
	WebView web;
	ProgressBar uno;
	Button home;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.paginafacebook);
		web = (WebView) findViewById(R.id.webview1);
		uno = (ProgressBar) findViewById(R.id.progressBar6);
		home = (Button) findViewById(R.id.btnHOME);
		home.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				finish();
				Intent intent1 = new Intent(PaginaFacebook.this,Principal.class);
				intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent1);
			}
		});
		
		Bundle extras1 = getIntent().getExtras();
		eve_facebook = extras1.getString("query22");
		
		if (!eve_facebook.startsWith(HTTP) && !eve_facebook.startsWith(HTTPS)) {
			eve_facebook = HTTP + eve_facebook;
		}
		String url = ""+eve_facebook;
		Log.i("pagina web", ""+eve_facebook);
		
		WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        web.getSettings().setPluginsEnabled(true);
        web.setWebViewClient(new WebViewClient(){
        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
			@Override
			public void onPageFinished(WebView view, String url) {
				uno.setVisibility(View.GONE);
			}
        });
		web.loadUrl(url);
//		startActivity(intent);
		new verMiWeb();
	}

	private class verMiWeb extends WebViewClient {
	    @Override
	    public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        view.loadUrl(url);
	        return true;
	    }
	}
	
	public static void deleteCache(Context context) {
	    try {
	        File dir = context.getCacheDir();
	        if (dir != null && dir.isDirectory()) {
	            deleteDir(dir);
	        }
	    } catch (Exception e) {}
	}

	public static boolean deleteDir(File dir) {
	    if (dir != null && dir.isDirectory()) {
	        String[] children = dir.list();
	        for (int i = 0; i < children.length; i++) {
	            boolean success = deleteDir(new File(dir, children[i]));
	            if (!success) {
	                return false;
	            }
	        }
	    }
	    return dir.delete();
	}
}
